#pragma once

#include <MCF/Code/StdMCF.hpp>
#include <MCF/Code/AbstractThreadClass.hpp>
#include <MCF/Code/AbstractTimerClass.hpp>
#include "VGAClass.hpp"

class VGAClass::_VGAThreadClass sealed : public MCF::AbstractThreadClass {
private:
	static const std::size_t _REFRESH_RATE = 60;
private:
	class _RefreshTimerClass sealed : public MCF::AbstractTimerClass {
	private:
		MCF::Event _m_OwnedEvent;
	public:
		_RefreshTimerClass(std::size_t uRefreshRate) : AbstractTimerClass(uRefreshRate), _m_OwnedEvent(false, true) { }
		~_RefreshTimerClass(){ }
	protected:
		virtual void _TimerLoop() override {
			_m_OwnedEvent.Set();
		}
	public:
		void Wait(){
			_m_OwnedEvent.Wait();
		}
	};
private:
	VGAClass *const _m_lpOwner;

	_RefreshTimerClass *_m_lpRefreshTimer;

	MCF::CriticalSection _m_csLock;
	HDC _m_hFrontBuffer;
	HDC _m_hBackBuffer;
public:
	_VGAThreadClass(VGAClass *lpOwner);
	~_VGAThreadClass();
protected:
	virtual int _ThreadProc() override;
public:
	HDC LockMemDC() const;
	void UnlockMemDC() const;
};
